<?php
 class AEmailMarketing extends CActiveRecord{
    public static function model($className = __CLASS__) {
        return parent::model ( $className );
    }


    // goi den bang can ket noi   
    public function tableName() {                  
        return 'c_email_marketing';
    }
    
    public function getDataLinkFooter($page,$row_per_page){
        $sql = "SELECT count(id) as count FROM c_email_marketing WHERE type = 0";
        $command = Yii::app()->db->createCommand($sql);
        $data_count = $command->queryRow();
        $max_page = ceil($data_count["count"]/$row_per_page);
        $first = ($page-1)*$row_per_page;
        $sql = "SELECT * FROM c_email_marketing WHERE type = 0 ORDER BY id DESC LIMIT ".$first.",".$row_per_page."";
        $command = Yii::app()->db->createCommand($sql);
        $data = $command->queryAll();
        return array($data,$data_count["count"],$max_page);
    }
    
    public function getDataById($id){
        $sql = "SELECT * FROM c_email_marketing WHERE id = ".intval($id);
        $command = Yii::app()->db->createCommand($sql);
        $data = $command->queryRow();
        return $data;
    }
    
    public function getAllDataOtherType($type){
        $sql = "SELECT * FROM c_email_marketing WHERE type <> 0";
        $command = Yii::app()->db->createCommand($sql);
        $rows = $command->queryAll();
        for($i=0;$i<count($rows);$i++){
            $data[$rows[$i]["type"]] = $rows[$i];
        }
        return isset($data) ? $data:array();
    }
 }
